/* 
 * File:   Scanner.h
 * Author: michele
 *
 * Created on February 15, 2012, 2:01 PM
 */

#ifndef SCANNER_H
#define	SCANNER_H

#include "enums.h"
#include "Writer.h"
#include "ExtendedSymbolTable.h"

class Scanner {
public:
    virtual ~Scanner();
    bool scan();
    Scanner(const char filename[]);
    Keywords getnextsym();
    

private:
    int cur_line, cur_col, err_line, err_col; /* For error reporting */
    int num;                                  /* Last number read stored here, for the parser */
    string id;
    std::ifstream myfile;
    /* Last identifier read stored here, for the parser */
    
    std::map<std::string, Keywords> Identifiers;
    std::map<Keywords,std::string> Ops;
    std::map<Keywords,std::string> Boolvals;
    std::map<Keywords,std::string> Typ;
    std::map<Keywords,std::string> IOrouts;
    std::map<std::string,Keywords> Keyws;
    
    void init_keywords();
    int init_scan(const char fn[]);
    bool scan_int(std::string in,int& out);
    bool scan_bool(std::string in);
    char scan_alpha(int in);
    pair<map<string,Types>::iterator,bool> scan_id(string in,Types type);
    void error_recover(std::ifstream& mystream);
    bool is_blank(char ch);
    bool is_end(char ch);
    std::string scan_word(char ch);
    bool scan_id(std::string in);
    bool remove_comments();
    
};

#endif	/* SCANNER_H */

